package main

import (
	"context"
	"embed"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"

	"sfLauncher/launch"
	"sfLauncher/preference"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	// Create an instance of the app structure
	placeholder := launch.NewPlaceHolder()
	pref := preference.NewPreference()
	vs := launch.NewVersion()

	// Create application with options
	err := wails.Run(&options.App{
		Title:         "sfLauncher",
		Width:         1024,
		Height:        768,
		Frameless:     true,
		DisableResize: true,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		OnStartup: func(ctx context.Context) {
			placeholder.SetContext(ctx)
			pref.SetContext(ctx)
			vs.SetContext(ctx)
		},
		OnShutdown: func(ctx context.Context) {
			pref.SaveToLocal()
		},
		Bind: []interface{}{
			placeholder,
			pref,
			vs,
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
